package com.itheima.demo6tcp3;

import java.io.DataInputStream;
import java.io.InputStream;
import java.net.Socket;

public class ServerReader extends Thread{
    private Socket socket;
    public ServerReader(Socket socket) {
        this.socket = socket;
    }
    @Override
    public void run(){
        try {
//        3、获取输入流对象，接收数据
            InputStream is = socket.getInputStream();
//        4、把字节输入流包装成特殊数据输入流
            DataInputStream dis = new DataInputStream(is);
//        5、读取数据
            String name= null;
            while (true) {
                name = dis.readUTF();
                System.out.println("name="+name);
    //         6、客户端的ip和端口
                System.out.println(socket.getInetAddress());
                System.out.println("客户端的端口号："+socket.getPort());
                System.out.println("========================================");
            }
        } catch (Exception e) {
            System.out.println("客户"+socket.getPort()+"端断开了连接");
        }
    }
}
